package com.gongguizhijia.Util;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.gongguizhijia.Constant.Constants;
import com.gongguizhijia.pojo.*;
import com.gongguizhijia.pojo.CvEcuConfigInfo;
import com.gongguizhijia.pojo.DataStreamModel;
import com.gongguizhijia.pojo.FaultCodeDescModel;
import com.gongguizhijia.pojo.VersionInfoModel;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.io.FileOutputStream;
import java.util.*;

import static java.util.Arrays.copyOf;

/**
 * @author Chenglei
 * @date 2021/6/2 9:06
 */
public class ExportExcel {

    //东风专检
    public static void ExportDfExcel(Map<String, List> map, String ecuCode,String systemId, String communicationProtocol) throws Exception {



        if (ecuCode == null) {
            return;
        }

        //获取桌面路径
        File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
        String desktopPath = desktopDir.getAbsolutePath();

        //文件名称
        String fileName = desktopPath + "\\test\\"+systemId+"-" + communicationProtocol + ".xlsx";
        File file = new File(fileName);
        //如果已经存在就删除
        if (file.exists()) {
            file.delete();
        }

        FileOutputStream outputStream = new FileOutputStream(file);
        ExcelWriter excelWriter = EasyExcelFactory.getWriter(outputStream);

        //字体
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontName("宋体");

        //数据
        //获取基本信息概览数据
        List<List<Object>> systemInfo = getSystemInfo(map, ecuCode);
        //获取进系统命令数据
        List<List<Object>> systemCommand = getSystemCommand(map, ecuCode);
        //获取故障码命令数据
        List<List<Object>> failCodeCommand = getFailCodeCommand(map, ecuCode);
        //获取故障码描述数据
        List<FaultCodeDescModel> failCodeDesc = getFailCodeDesc(map, ecuCode);
        //获取数据流数据
        List<DataStreamModel> dataStream = getDataStream(map, ecuCode);
        //获取故版本信息数据
        List<VersionInfoModel> versionInfo = getVersionInfo(map, ecuCode);

        //表单
        //基本信息概览
        Sheet sheet1 = new Sheet(1, 0);
        sheet1.setSheetName("基本信息概览");
        excelWriter.write1(systemInfo, sheet1);

        //进系统命令
        Sheet sheet2 = new Sheet(2, 0);
        sheet2.setSheetName("进系统命令");
        excelWriter.write1(systemCommand, sheet2);

        //故障码命令
        Sheet sheet3 = new Sheet(3, 0);
        sheet3.setSheetName("故障码命令");
        excelWriter.write1(failCodeCommand, sheet3);

        //故障码描述
        WriteSheet writeSheet4 = EasyExcel.writerSheet(4, "故障码描述").head(FaultCodeDescModel.class).build();
        if(!failCodeDesc.isEmpty()){
            excelWriter.write(failCodeDesc, writeSheet4);
        }

        //数据流
        WriteSheet writeSheet5 = EasyExcel.writerSheet(5, "数据流").head(DataStreamModel.class).build();
        if (!dataStream.isEmpty()){
            excelWriter.write(dataStream, writeSheet5);
        }

        //版本信息
        WriteSheet writeSheet6 = EasyExcel.writerSheet(6, "版本信息").head(VersionInfoModel.class).build();
        if(!versionInfo.isEmpty()){
            excelWriter.write(versionInfo, writeSheet6);
        }



        excelWriter.finish();
    }


    //获取16进制文件集
    public static String[] getArr(){

        String[] arr = new String[]{"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
                "X0A", "X0B", "X0C", "X0D", "X0E", "X0F","X10"};
        arr=copyOf(arr,1984);

        for (int i = 16; i <= 1984; i++){
            arr[i - 1] = "X"+ IntToHex.intToHex(i);
        }

        return arr;
    }


    public static final String[] arr1 = getArr();
//            {"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
//            "X0A", "X0B", "X0C", "X0D", "X0E", "X0F"
//            , "X10", "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19"
//            , "X1A", "X1B", "X1C", "X1D", "X1E", "X1F",
//            "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", "X29"
//            , "X2A", "X2B", "X2C", "X2D", "X2E", "X2F",
//            "X30", "X31", "X32", "X33", "X34", "X35", "X36", "X37", "X38", "X39"
//            , "X3A", "X3B", "X3C", "X3D", "X3E", "X3F",
//            "X40", "X41", "X42", "X43", "X44", "X45", "X46", "X47", "X48", "X49"
//            , "X4A", "X4B", "X4C", "X4D", "X4E", "X4F",
//                    "X50", "X51", "X52", "X53", "X54", "X55", "X56", "X57", "X58", "X59"
//                    , "X5A", "X5B", "X5C", "X5D", "X5E", "X5F",
//                    "X60", "X61", "X62", "X63", "X64", "X65", "X66", "X67", "X68", "X69"
//    };

    //版本信息
    public static List<VersionInfoModel> getVersionInfo(Map<String, List> map, String ecuCode) throws Exception {
        //获取数据
        List<CvEcuId> listCvEcuIds = map.get(Constants.LIST_ID);
        //获取符合ecuCode数据集
        List<CvEcuId> cvEcuIds = new ArrayList<>();

        for (CvEcuId cvEcuId : listCvEcuIds) {
            if (ecuCode.equals(cvEcuId.getEcuCode())) {
                cvEcuIds.add(cvEcuId);
            }
        }

        //获取ApplicationProtocol进行did拼接准备
        List<CvEcuConfigInfo> listConfigInfo = map.get(Constants.LIST_CONFIG_INFO);
        CvEcuConfigInfo cvEcuConfigInfo = new CvEcuConfigInfo();

        for (CvEcuConfigInfo configInfo : listConfigInfo) {
            if (ecuCode.equals(configInfo.getEcuCode())) {
                cvEcuConfigInfo = configInfo;
            }
        }


        //返回结果集
        List<VersionInfoModel> result = new ArrayList<>();
        for (CvEcuId cvEcuId : cvEcuIds) {
            VersionInfoModel versionInfoModel = new VersionInfoModel();
            versionInfoModel.setKvId("");
            versionInfoModel.setDesc(cvEcuId.getSubitemNameCn());
            versionInfoModel.setAnalyticFormula("");
            versionInfoModel.setUnit("");
            versionInfoModel.setIsShow("是");
            versionInfoModel.setRemark("东风");

            String did = cvEcuId.getDid();
            String newDid = null;
            //判断命令是否需要补足
            if(did.length()%2 != 0){
                newDid = did.substring(0,did.length() - 1) +"0"+ did.substring(did.length()-1,did.length()).toUpperCase();
            }else {
                newDid = did.toUpperCase();
            }

            //拼接did
            if ("ISO14229".equals(cvEcuConfigInfo.getApplicationProtocol())) {
                versionInfoModel.setOrder("22 " + getFileAddSpace(newDid));
            } else if ("ISO14230".equals(cvEcuConfigInfo.getApplicationProtocol())) {
                versionInfoModel.setOrder("1A " + getFileAddSpace(newDid));
            } else if ("1939".equals(cvEcuConfigInfo.getApplicationProtocol())) {
                versionInfoModel.setOrder(getFileAddSpace(newDid));
            }else {
                versionInfoModel.setOrder(getFileAddSpace(newDid));
            }

            //获取Decode
            if ("ASCII".equals(cvEcuId.getSubitemDataType())) {
                versionInfoModel.setDecode("RK002");
                versionInfoModel.setAnalyticFormula(getABHFormula(cvEcuId, versionInfoModel.getOrder()));
            } else if ("BCD".equals(cvEcuId.getSubitemDataType()) || "HEX".equals(cvEcuId.getSubitemDataType())) {
                versionInfoModel.setDecode("RK001");
                versionInfoModel.setAnalyticFormula(getABHFormula(cvEcuId, versionInfoModel.getOrder()));
            } else if ("数值".equals(cvEcuId.getSubitemDataType())) {
                versionInfoModel.setDecode("RD001");
                versionInfoModel.setAnalyticFormula(getValueFormula(cvEcuId, versionInfoModel.getOrder()));
            } else {
                versionInfoModel.setDecode("暂不支持的解析方式:" + cvEcuId.getSubitemDataType());
                String other = getOther(cvEcuId, versionInfoModel.getOrder());
                versionInfoModel.setAnalyticFormula("取位结果:" + other);
            }

            result.add(versionInfoModel);
        }
        return result;
    }

    //数据流
    public static List<DataStreamModel> getDataStream(Map<String, List> map, String ecuCode) throws Exception {
        //获取数据
        List<CvEcuConfigInfo> listConfigInfo = map.get(Constants.LIST_CONFIG_INFO);
        List<CvEcuMntsignal> listMntsignal = map.get(Constants.LIST_MNTSIGNAL);
        List<CvEcuConversion> listConversion = map.get(Constants.LIST_CONVERSION);
        List<CvEcuConversionDetail> listConversionDetail = map.get(Constants.LIST_CONVERSION_DETAIL);

        //数据处理 取出需要的数据
        List<CvEcuMntsignal> cvEcuMntsignals = new ArrayList<>();
        ArrayList<CvEcuConversion> cvEcuConversions = new ArrayList<>();
        ArrayList<CvEcuConversionDetail> cvEcuConversionDetails = new ArrayList<>();

        CvEcuConfigInfo cvEcuConfigInfoResult = null;
        for (CvEcuConfigInfo cvEcuConfigInfo : listConfigInfo) {
            if (ecuCode.equals(cvEcuConfigInfo.getEcuCode())) {
                //根据ecuConfigId 获取CvEcuConfigInfo 对象
                cvEcuConfigInfoResult = cvEcuConfigInfo;
                for (CvEcuMntsignal cvEcuMntsignal : listMntsignal) {
                    if (cvEcuConfigInfoResult.getEcuCode().equals(cvEcuMntsignal.getEcuCode()) && ("1").equals(cvEcuMntsignal.getEnableFlag())) {
                        cvEcuMntsignals.add(cvEcuMntsignal);
                    }
                }
            }
        }

        for (CvEcuConversion cvEcuConversion : listConversion) {
            if (ecuCode.equals(cvEcuConversion.getEcuCode())) {
                cvEcuConversions.add(cvEcuConversion);
            }
            for (CvEcuConversionDetail cvEcuConversionDetail : listConversionDetail) {
                if (cvEcuConversion.getConversionId().equals(cvEcuConversionDetail.getConversionId())) {
                    cvEcuConversionDetails.add(cvEcuConversionDetail);
                }
            }
        }

        List<DataStreamModel> dataStreamModels = new ArrayList<>();

        for (CvEcuMntsignal cvEcuMntsignal : cvEcuMntsignals) {

            //解析方式
            for (CvEcuConversion cvEcuConversion : cvEcuConversions) {
                if (cvEcuMntsignal.getSubitemTransWay().equals(cvEcuConversion.getConversionName()) && cvEcuMntsignal.getEcuCode().equals(cvEcuConversion.getEcuCode())) {

                    DataStreamModel dataStreamModel = new DataStreamModel();
                    dataStreamModel.setKvId("");
                    dataStreamModel.setDesc(cvEcuMntsignal.getSubitemNameCn());
                    dataStreamModel.setUnit(cvEcuMntsignal.getSubitemUnit());
                    dataStreamModel.setIsShow("是");
                    dataStreamModel.setRemark("东风");
                    dataStreamModel.setDigit("2");

                    String did = cvEcuMntsignal.getDid();
                    String newDid = null;
                    //判断命令是否需要补足
                    if(did.length()%2 != 0){
                        newDid = did.substring(0,did.length() - 1) +"0"+ did.substring(did.length()-1,did.length());
                    }else {
                        newDid = did;
                    }
                    //设置命令 拼接
                    if ("ISO14229".equals(cvEcuConfigInfoResult.getApplicationProtocol())) {
                        dataStreamModel.setOrder("22" +" "+ getFileAddSpace(newDid));
                    } else if ("ISO14230".equals(cvEcuConfigInfoResult.getApplicationProtocol())) {
                        dataStreamModel.setOrder("21"+" "+ getFileAddSpace(newDid));
                    } else {
                        dataStreamModel.setOrder(getFileAddSpace(newDid));
                    }

                    if ("ASCII".equals(cvEcuConversion.getConversionType())) {
                        //设置解析规则
                        dataStreamModel.setDecode("RK002");
                        //设置解析公式
                        String assciiResult = getForASCII(cvEcuMntsignal, dataStreamModel);
                        dataStreamModel.setAnalyticFormula(assciiResult);
                    } else if ("FLOAT".equals(cvEcuConversion.getConversionType())) {
                        dataStreamModel.setDecode("RD022");
                        //解析公式
                        String floatResult = getForFloat(cvEcuMntsignal, dataStreamModel);
                        dataStreamModel.setAnalyticFormula(floatResult);
                    } else if ("LINEAR".equals(cvEcuConversion.getConversionType())) {
                        if (Integer.valueOf(cvEcuMntsignal.getSubitemDataLength()) % 8 == 0 && Integer.valueOf(cvEcuMntsignal.getSubitemStartPlace()) % 8 == 0) {
                            dataStreamModel.setDecode("RD001");
                            //解析公式
                            String linearForRD001Result = getForLinearRd001(cvEcuMntsignal, dataStreamModel, cvEcuConversion);
                            dataStreamModel.setAnalyticFormula(linearForRD001Result);
                        } else {
                            dataStreamModel.setDecode("RD012");
                            //解析公式
                            String linearForRD012Result = getForLinearRd012(cvEcuMntsignal, dataStreamModel, cvEcuConversion);
                            dataStreamModel.setAnalyticFormula(linearForRD012Result);
                        }
                    } else if ("TAB_VERB".equals(cvEcuConversion.getConversionType())) {
                        dataStreamModel.setDecode("RD012");
                        //解析公式
                        String tabVerbResult = getForTabVerb(cvEcuMntsignal, dataStreamModel, cvEcuConversion, cvEcuConversionDetails);
                        dataStreamModel.setAnalyticFormula(tabVerbResult);
                    } else {
                        dataStreamModel.setDecode("暂无相关规则");
                        //  无对应规则   放取位
                        String otherResult = getForOther(cvEcuMntsignal, dataStreamModel, cvEcuConversion, cvEcuConversionDetails);
                        dataStreamModel.setAnalyticFormula("取位结果:"+otherResult);
                    }
                    dataStreamModels.add(dataStreamModel);
                }
            }
        }
        return dataStreamModels;
    }

    //故障码描述
    public static List<FaultCodeDescModel> getFailCodeDesc(Map<String, List> map, String ecuCode) {

        List<CvEcuDtc> listDtc = map.get(Constants.LIST_DTC);

        List<CvEcuDtc> ecuDtcList = new ArrayList<>();
        for (CvEcuDtc cvEcuDtc : listDtc) {
            if (ecuCode.equals(cvEcuDtc.getEcuCode())) {
                ecuDtcList.add(cvEcuDtc);
            }
        }

        List<FaultCodeDescModel> faultCodeDescModels = new ArrayList<>();

        for (CvEcuDtc ecuDtc : ecuDtcList) {
            FaultCodeDescModel faultCodeDescModel = new FaultCodeDescModel();
            faultCodeDescModel.setEcode(ecuDtc.getDtcValue());
            faultCodeDescModel.setPcode("SPN" + ecuDtc.getSpn() + " " + "FMI" + ecuDtc.getFmi());
            faultCodeDescModel.setDesc(ecuDtc.getDescCn());
            faultCodeDescModel.setIsShow("是");
            faultCodeDescModel.setRemark("东风");
            faultCodeDescModels.add(faultCodeDescModel);
        }
        return faultCodeDescModels;
    }

    //故障码命令
    public static List<List<Object>> getFailCodeCommand(Map<String, List> map, String ecuCode) throws Exception {
        List<List<Object>> result = new ArrayList<>();

        List<Object> list1 = new ArrayList<>();
        list1.add("故障码读取");
        list1.add("命令");
        list1.add("解析类型");
        list1.add("解析公式");
        list1.add("备注");
        result.add(list1);

        List<Object> list2 = new ArrayList<>();
        list2.add("");
        list2.add("");//A9 81 12
        list2.add("");//RB001
        list2.add("");//{"length": "44", "position": "06", "rlength": "04", "staflag": "[X00X01]&0xFFFF", "state": "X03&0B=0B:1;0"}
        list2.add("");
        result.add(list2);

        List<Object> list3 = new ArrayList<>();
        list3.add("故障码清除");
        list3.add("命令");
        list3.add("备注");
        result.add(list3);

        List<Object> list4 = new ArrayList<>();
        list4.add("");
        list4.add("");//4
        list4.add("");
        result.add(list4);
        return result;
    }

    //进系统命令
    public static List<List<Object>> getSystemCommand(Map<String, List> map, String ecuCode) throws Exception {

        //数据处理
        List<CvEcuConfigInfo> listConfigInfo = map.get(Constants.LIST_CONFIG_INFO);

        CvEcuConfigInfo cvEcuConfigInfoResult = null;
        for (CvEcuConfigInfo cvEcuConfigInfo : listConfigInfo) {
            if (ecuCode.equals(cvEcuConfigInfo.getEcuCode())) {
                cvEcuConfigInfoResult = cvEcuConfigInfo;
            }
        }

        String channel = cvEcuConfigInfoResult.getChannel();
        String channelResult = null;
        if ("K".equals(channel)) {
            channelResult = "7";
        }
        if ("CAN0".equals(channel)) {
            channelResult = "6/14";
        }
        if ("CAN1".equals(channel)) {
            channelResult = "3/11";
        }
        if ("CAN2".equals(channel)) {
            channelResult = "1/9";
        }

        String applicationProtocol = cvEcuConfigInfoResult.getApplicationProtocol();
        String didResult = null;
        if ("ISO14229".equals(applicationProtocol)) {
            didResult = "22" + " " + getFileAddSpace(cvEcuConfigInfoResult.getDid());
        }
        if ("ISO14230".equals(applicationProtocol)) {
            didResult = "1A" + " " + getFileAddSpace(cvEcuConfigInfoResult.getDid());
        }

        //表单处理
        List<List<Object>> result = new ArrayList<>();

        List<Object> list1 = new ArrayList<>();
        list1.add("组序号");
        list1.add("类型");
        result.add(list1);

        List<Object> list2 = new ArrayList<>();
        list2.add("1");
        list2.add("针脚波特率配置");
        list2.add(channelResult);//通讯针脚
        list2.add(cvEcuConfigInfoResult.getBaudRate());//波特率
        result.add(list2);

        List<Object> list3 = new ArrayList<>();
        list3.add("1");
        list3.add("帧ID");
        list3.add(cvEcuConfigInfoResult.getResponseId());//接收帧地址
        list3.add(cvEcuConfigInfoResult.getRequestId());//发送帧地址
        list3.add(cvEcuConfigInfoResult.getRequestId());//发送帧地址
        result.add(list3);

        List<Object> list4 = new ArrayList<>();
        list4.add("1");
        list4.add("初始化");
        list4.add("");//10 83
        result.add(list4);

        List<Object> list5 = new ArrayList<>();
        list5.add("1");
        list5.add("退出");
        list5.add("");//10 81
        result.add(list5);

        List<Object> list6 = new ArrayList<>();
        list6.add("1");
        list6.add("通讯保持");
        list6.add("");//3E
        result.add(list6);

        List<Object> list7 = new ArrayList<>();
        list7.add("1");
        list7.add("版本识别");
        list7.add(didResult);//进系统命令
        result.add(list7);

        return result;
    }

    //基本信息预览
    public static List<List<Object>> getSystemInfo(Map<String, List> map, String ecuCode) throws Exception {

        List<List<Object>> result = new ArrayList<>();
        List<CvEcuConfigInfo> listConfigInfo = map.get(Constants.LIST_CONFIG_INFO);
        CvEcuConfigInfo cvEcuConfigInfo = new CvEcuConfigInfo();

        for (CvEcuConfigInfo configInfo : listConfigInfo) {
            if (ecuCode.equals(configInfo.getEcuCode())) {
                cvEcuConfigInfo = configInfo;
            }
        }


        //填充单元格
        List<DataStreamModel> dataStream = getDataStream(map, ecuCode);
        List<VersionInfoModel> versionInfo = getVersionInfo(map, ecuCode);
        List<FaultCodeDescModel> failCodeDesc = getFailCodeDesc(map, ecuCode);


        List<Object> list1 = new ArrayList<>();
        list1.add("系统信息");
        list1.add(cvEcuConfigInfo.getEcuName());
        result.add(list1);

            if (!versionInfo.isEmpty()){
                List<Object> list2 = new ArrayList<>();
                list2.add("预读取脚本");
                list2.add("c1");
                list2.add("c2");
                result.add(list2);

                List<Object> list3 = new ArrayList<>();
                list3.add("");
                list3.add("SCRIPI 000022");
                list3.add("9");
                result.add(list3);

                List<Object> list10 = new ArrayList<>();
                list10.add("版本信息PRI");
                list10.add("PRI");
                list10.add("协议");//可补充单元格数据
                result.add(list10);


                List<Object> list11 = new ArrayList<>();
                list11.add("");
                list11.add("0");
                list11.add("");
                result.add(list11);

                List<Object> list12 = new ArrayList<>();
                list12.add("");
                list12.add("1");
                list12.add(getCommunicationProtocol(map, ecuCode));
                result.add(list12);

            }

        if (!failCodeDesc.isEmpty()){
            List<Object> list4 = new ArrayList<>();
            list4.add("故障码PRI");
            list4.add("PRI");
            list4.add("协议");//可补充单元格数据
            result.add(list4);

            List<Object> list5 = new ArrayList<>();
            list5.add("");
            list5.add("0");
            list5.add("");
            result.add(list5);

            List<Object> list6 = new ArrayList<>();
            list6.add("");
            list6.add("1");
            list6.add(getCommunicationProtocol(map, ecuCode));
            result.add(list6);
        }


        if (!dataStream.isEmpty()){
            List<Object> list7 = new ArrayList<>();
            list7.add("数据流PRI");
            list7.add("PRI");
            list7.add("协议");//可补充单元格数据
            result.add(list7);

            List<Object> list8 = new ArrayList<>();
            list8.add("");
            list8.add("0");
            list8.add("");
            result.add(list8);

            List<Object> list9 = new ArrayList<>();
            list9.add("");
            list9.add("1");
            list9.add(getCommunicationProtocol(map, ecuCode));
            result.add(list9);
        }
        return result;
    }

    /**
     * 去除 多于的 0
     * @param result
     * @return
     */
    public static String subNumberText(String result) {
        if (result == null) {
            return "";
        }
        if (result.contains(".")) {// 是小数
            while (true) {
                if (result.charAt(result.length() - 1) == '0')
                    result = result.substring(0, result.length() - 1);
                else {
                    if (result.endsWith(".")) {
                        result = result.substring(0, result.length() - 1);
                    }
                    break;
                }

            }

        }
        return result;
    }
    /**
     * 其他  规则
     *
     * @param cvEcuMntsignal
     * @param dataStreamModel
     * @param cvEcuConversion
     * @param cvEcuConversionDetails
     * @return
     */
    private static String getForOther(CvEcuMntsignal cvEcuMntsignal, DataStreamModel dataStreamModel, CvEcuConversion cvEcuConversion, ArrayList<CvEcuConversionDetail> cvEcuConversionDetails) {
        if (cvEcuMntsignal.getSubitemStartPlace() == null) {
            return "表格SubitemStartPlace数据为空=》参数有误";
        }

        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuMntsignal.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuMntsignal.getSubitemDataLength());

        //获取value_a  value_b
        String value_a1 = cvEcuConversion.getValueA();
        String value_a = ExportExcel.subNumberText(value_a1);
        // String value_a = value_a1.split("\\.")[0];
        String value_b1 = cvEcuConversion.getValueB();
        String value_b = ExportExcel.subNumberText(value_b1);
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        Integer subitemDataLengthResult = 0;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 != 0) {
                subitemStartPlace = subitemStartPlace / 8 + 1;
            }else{
                subitemStartPlace = subitemStartPlace / 8;
            }
            Integer orderLength = 0;
            if (dataStreamModel.getOrder().replace(" ","").length()%2!=0){
                orderLength =(dataStreamModel.getOrder().replace(" ","").length() / 2) +1;
            }else{
                orderLength =  dataStreamModel.getOrder().replace(" ","").length() / 2;
            }
            Integer startPosition = subitemStartPlace + orderLength  + 06;
            //转换成16进制
            hexStartPosition = IntToHex.intToHex(startPosition);
            if (hexStartPosition.length() <= 1) {
                hexStartPosition = "0" + hexStartPosition;
            }
            //取几位
            if(subitemDataLength%8!=0){
                subitemDataLengthResult = subitemDataLength / 8 + 1;
            }else{
                subitemDataLengthResult = subitemDataLength / 8;
            }
        }
        String[] arr = arr1;
//        String[] arr = {"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
//                "X0A", "X0B", "X0C", "X0D", "X0E", "X0F"
//                , "X10", "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19"
//                , "X1A", "X1B", "X1C", "X1D", "X1E", "X1F",
//                "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", "X29"
//        };
        String startPositionSub = "X" + hexStartPosition;
        String result = "";
        int iForRsult = 0;
        for (int i = 0; i < arr.length; i++) {
            if (startPositionSub.equals(arr[i])) {
                iForRsult = i;
            }
        }

        for (int i = iForRsult; i < (iForRsult + subitemDataLengthResult); i++) {
            result += arr[i];
        }

        return result;
    }

    /**
     * TAB_VERB RD012
     *
     * @param cvEcuMntsignal
     * @param dataStreamModel
     * @param cvEcuConversion
     * @param cvEcuConversionDetails
     * @return
     */
    private static String getForTabVerb(CvEcuMntsignal cvEcuMntsignal, DataStreamModel dataStreamModel, CvEcuConversion cvEcuConversion, List<CvEcuConversionDetail> cvEcuConversionDetails) {
        if (cvEcuMntsignal.getSubitemStartPlace() == null) {
            return "表格SubitemStartPlace数据为空=》参数有误";
        }
        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuMntsignal.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuMntsignal.getSubitemDataLength());
        //获取cvEcuConversionId
        String conversionId = cvEcuConversion.getConversionId();

        Map<String, String> map = new HashMap<>();
        for (CvEcuConversionDetail cvEcuConversionDetail : cvEcuConversionDetails) {
            if (conversionId.equals(cvEcuConversionDetail.getConversionId())) {
                String tabSeq = cvEcuConversionDetail.getTabSeq();
                String tabValue = cvEcuConversionDetail.getTabValue();
                map.put(tabSeq, tabValue);
            }
        }
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        Integer subitemDataLengthResult = 0;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 == 0 && subitemDataLength % 8 == 0) {
                Integer orderLength = 0;
                if (dataStreamModel.getOrder().replace(" ","").length()%2!=0){
                    orderLength =(dataStreamModel.getOrder().replace(" ","").length() / 2) +1;
                }else{
                    orderLength =  dataStreamModel.getOrder().replace(" ","").length() / 2;
                }

                Integer startPosition = subitemStartPlace / 8 + orderLength + 06;
                //转换成16进制
                hexStartPosition = IntToHex.intToHex(startPosition);
                if (hexStartPosition.length() <= 1) {
                    hexStartPosition = "0" + hexStartPosition;
                }
                 //取几位
                if(subitemDataLength%8!=0){
                    subitemDataLengthResult = subitemDataLength / 8 + 1;
                }else{
                    subitemDataLengthResult = subitemDataLength / 8;
                }
            }
        }
        String[] arr = arr1;
//        String[] arr = {"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
//                "X0A", "X0B", "X0C", "X0D", "X0E", "X0F"
//                , "X10", "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19"
//                , "X1A", "X1B", "X1C", "X1D", "X1E", "X1F",
//                "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", "X29"
//        };
        String startPositionSub = "X" + hexStartPosition;
        String result = "";
        int iForRsult = 0;
        for (int i = 0; i < arr.length; i++) {
            if (startPositionSub.equals(arr[i])) {
                iForRsult = i;
            }
        }

        for (int i = iForRsult; i < (iForRsult + subitemDataLengthResult); i++) {
            result += arr[i];
        }

        String result2 = "";
        for (String tabSeq : map.keySet()) {
            String tabValue = map.get(tabSeq);
            // &FF=03:故障状态;  &FF=00:待命状态;  &FF=04:禁用;   &FF=01:激活状态;
            tabSeq =  ExportExcel.subNumberText(tabSeq);
            if (tabSeq.length()==1){
                tabSeq = "0"+tabSeq;
            }
            result2 += "&FF=" + tabSeq + ":" + tabValue + ";";
        }
        String formula = "{\"Switch_Type\":\"" + result + result2 + "未知\"}";
        return formula;
    }

    /**
     * Linear Rd012
     *
     * @param cvEcuMntsignal
     * @param dataStreamModel
     * @param cvEcuConversion
     * @return
     */
    private static String getForLinearRd012(CvEcuMntsignal cvEcuMntsignal, DataStreamModel dataStreamModel, CvEcuConversion cvEcuConversion) {
        // TODO: 2021/6/3
        if (cvEcuMntsignal.getSubitemStartPlace() == null) {
            return "表格SubitemStartPlace数据为空=》参数有误";
        }
        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuMntsignal.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuMntsignal.getSubitemDataLength());
        //获取value_a  value_b
        String value_a1 = cvEcuConversion.getValueA();
        String value_a = ExportExcel.subNumberText(value_a1);
        // String value_a = value_a1.split("\\.")[0];
        String value_b1 = cvEcuConversion.getValueB();
        String value_b = ExportExcel.subNumberText(value_b1);
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        if (subitemStartPlace != null) {
            //todo:
            if (subitemStartPlace % 8 != 0) {
                subitemStartPlace = subitemStartPlace / 8 + 1;
            }else{
                subitemStartPlace = subitemStartPlace / 8;
            }
            Integer orderLength = 0;
            if (dataStreamModel.getOrder().replace(" ","").length()%2!=0){
                orderLength =(dataStreamModel.getOrder().replace(" ","").length() / 2) +1;
            }else{
                orderLength =  dataStreamModel.getOrder().replace(" ","").length() / 2;
            }
            Integer startPosition = subitemStartPlace +  orderLength + 06;
            //转换成16进制
            hexStartPosition = IntToHex.intToHex(startPosition);
            if (hexStartPosition.length() <= 1) {
                hexStartPosition = "0" + hexStartPosition;
            }
            hexStartPosition = "X" + hexStartPosition;
        }
        String result = "";
        String[] arr = {"0", "0", "0", "0", "0", "0", "0", "0"};

        arr[subitemStartPlace % 8] = "1";
        for (int i = 0; i < arr.length; i++) {
            result += arr[i];
        }
        //二进制 转成十进制
        int parseInt = Integer.parseInt(result, 2);
        //转成16进制
        String hex = IntToHex.intToHex(parseInt);
        String formula = "{\"Switch_Type\":\"" + hexStartPosition + "&" + hex + "=" + hex + ":" + value_a + ";&" + hex + "=" + "00" + ":" + value_b + "\"}";
        return formula;
    }

    /**
     * Linear Rd001
     *
     * @param cvEcuMntsignal
     * @param dataStreamModel
     * @param cvEcuConversion
     * @return
     */
    private static String getForLinearRd001(CvEcuMntsignal cvEcuMntsignal, DataStreamModel dataStreamModel, CvEcuConversion cvEcuConversion) {
        if (cvEcuMntsignal.getSubitemStartPlace() == null) {
            return "表格SubitemStartPlace数据为空=》参数有误";
        }

        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuMntsignal.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuMntsignal.getSubitemDataLength());

        //获取value_a  value_b
        String value_a1 = cvEcuConversion.getValueA();
        String value_a = ExportExcel.subNumberText(value_a1);
        //Integer value_a_int = Integer.valueOf(value_a);
        // String value_a = value_a1.split("\\.")[0];
        String value_b1 = cvEcuConversion.getValueB();
        String value_b = ExportExcel.subNumberText(value_b1);
        //Integer value_b_int = Integer.valueOf(value_b);
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        Integer subitemDataLengthResult = 0;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 == 0 && subitemDataLength % 8 == 0) {
                Integer orderLength = 0;
                if (dataStreamModel.getOrder().replace(" ","").length()%2!=0){
                    orderLength =(dataStreamModel.getOrder().replace(" ","").length() / 2) +1;
                }else{
                    orderLength =  dataStreamModel.getOrder().replace(" ","").length() / 2;
                }
                Integer startPosition = subitemStartPlace / 8 +  orderLength + 06;
                //转换成16进制
                hexStartPosition = IntToHex.intToHex(startPosition);
                if (hexStartPosition.length() <= 1) {
                    hexStartPosition = "0" + hexStartPosition;
                }
                //取几位
                subitemDataLengthResult = subitemDataLength / 8;
            }
        }
//        String[] arr = {"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
//                "X0A", "X0B", "X0C", "X0D", "X0E", "X0F"
//                , "X10", "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19"
//                , "X1A", "X1B", "X1C", "X1D", "X1E", "X1F",
//                "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", "X29"
//        };
        String[] arr = arr1;
        String startPositionSub = "X" + hexStartPosition;
        String result = "";
        int iForRsult = 0;
        for (int i = 0; i < arr.length; i++) {
            if (startPositionSub.equals(arr[i])) {
                iForRsult = i;
            }
        }

        for (int i = iForRsult; i < (iForRsult + subitemDataLengthResult); i++) {
            result += arr[i];
        }

        if (value_a.startsWith("-")){
            value_a = "(" +  value_a + ")";
        }

        if(!value_b.startsWith("-")){
            value_b = "+" + value_b;
        }
        if ("+0".equals(value_b)){
            value_b = "";
        }



        String formula = "{\"Switch_Type\":\"[" + result + "]*" + value_a + value_b + "\"}";
        return formula;
    }

    /**
     * Float 解析公式方法
     *
     * @param cvEcuMntsignal
     * @param dataStreamModel
     * @return
     */
    private static String getForFloat(CvEcuMntsignal cvEcuMntsignal, DataStreamModel dataStreamModel) {
        if (cvEcuMntsignal.getSubitemStartPlace() == null) {
            return "表格SubitemStartPlace数据为空=》参数有误";
        }

        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuMntsignal.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuMntsignal.getSubitemDataLength());
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        Integer subitemDataLengthResult = 0;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 != 0) {
                subitemStartPlace = subitemStartPlace / 8 + 1;
            }else{
                subitemStartPlace = subitemStartPlace / 8;
            }
            Integer orderLength = 0;
            if (dataStreamModel.getOrder().replace(" ","").length()%2!=0){
                orderLength =(dataStreamModel.getOrder().replace(" ","").length() / 2) +1;
            }else{
                orderLength =  dataStreamModel.getOrder().replace(" ","").length() / 2;
            }
            Integer startPosition = subitemStartPlace +  orderLength + 06;
            //转换成16进制
            hexStartPosition = IntToHex.intToHex(startPosition);
            if (hexStartPosition.length() <= 1) {
                hexStartPosition = "0" + hexStartPosition;
            }
            //取几位
            if(subitemDataLength%8!=0){
                subitemDataLengthResult = subitemDataLength / 8 + 1;
            }else{
                subitemDataLengthResult = subitemDataLength / 8;
            }

        }
//        String[] arr = {"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
//                "X0A", "X0B", "X0C", "X0D", "X0E", "X0F"
//                , "X10", "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19"
//                , "X1A", "X1B", "X1C", "X1D", "X1E", "X1F",
//                "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", "X29"
//        };
        String[] arr = arr1;
        String startPositionSub = "X" + hexStartPosition;
        String result = "";
        int iForRsult = 0;
        for (int i = 0; i < arr.length; i++) {
            if (startPositionSub.equals(arr[i])) {
                iForRsult = i;
            }
        }

        for (int i = iForRsult; i < (iForRsult + subitemDataLengthResult); i++) {
            result += arr[i];
        }
        String formula = "{\"Switch_Type\":\"[" + result + "]\"}";
        return formula;
    }

    /**
     * ASCII  获取解析公式
     *
     * @param cvEcuMntsignal
     * @return
     */
    private static String getForASCII(CvEcuMntsignal cvEcuMntsignal, DataStreamModel dataStreamModel) {
        if (cvEcuMntsignal.getSubitemStartPlace() == null) {
            return "表格SubitemStartPlace数据为空=》参数有误";
        }
        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuMntsignal.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuMntsignal.getSubitemDataLength());
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        String hexEndPosition = null;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 == 0 && subitemDataLength % 8 == 0) {
                Integer orderLength = 0;
                if (dataStreamModel.getOrder().replace(" ","").length()%2!=0){
                    orderLength =(dataStreamModel.getOrder().replace(" ","").length() / 2) +1;
                }else{
                    orderLength =  dataStreamModel.getOrder().replace(" ","").length() / 2;
                }
                Integer startPosition = subitemStartPlace / 8 +  orderLength + 06;
                //转换成16进制
                hexStartPosition = IntToHex.intToHex(startPosition);
                if (hexStartPosition.length() <= 1) {
                    hexStartPosition = "0" + hexStartPosition;
                }
                Integer endPosition = startPosition + subitemDataLength / 8;
                //转换成16进制
                hexEndPosition = IntToHex.intToHex(endPosition);
                if (hexEndPosition.length() <= 1) {
                    hexEndPosition = "0" + hexEndPosition;
                }
            } else {
                Integer orderLength = 0;
                if (dataStreamModel.getOrder().replace(" ","").length()%2!=0){
                    orderLength =(dataStreamModel.getOrder().replace(" ","").length() / 2) +1;
                }else{
                    orderLength =  dataStreamModel.getOrder().replace(" ","").length() / 2;
                }
                // hexStartPosition = cvEcuMntsignal.getSubitemStartPlace(); // TODO: 2021/6/3
                Integer startPosition = 00 + orderLength + 06;
                //转换成16进制
                hexStartPosition = IntToHex.intToHex(startPosition);
                if (hexStartPosition.length() <= 1) {
                    hexStartPosition = "0" + hexStartPosition;
                }
                hexEndPosition = "FF";
            }

        }
        String formula = "{\"start_position\":\"" + hexStartPosition + "\",\"end_position\":\"" + hexEndPosition + "\"}";
        return formula;
    }


    //获取CommunicationProtocol属性
    public static String getCommunicationProtocol(Map<String, List> map, String ecuCode) {

        List<CvEcuConfigInfo> listConfigInfo = map.get(Constants.LIST_CONFIG_INFO);
        CvEcuConfigInfo cvEcuConfigInfo = new CvEcuConfigInfo();

        for (CvEcuConfigInfo configInfo : listConfigInfo) {
            if (ecuCode.equals(configInfo.getEcuCode())) {
                cvEcuConfigInfo = configInfo;
            }
        }

        //判断通讯协议
        String communicationProtocol = "";
        String applicationProtocol = cvEcuConfigInfo.getApplicationProtocol();
        String transportProtocol = cvEcuConfigInfo.getTransportProtocol();
        switch (applicationProtocol) {
            case "ISO14229":
                communicationProtocol = "UDS";
                break;
            case "ISO14230":
                if ("ISO15765-2".equals(transportProtocol)) {
                    communicationProtocol = "KWP2000_CAN";
                }
                if ("ISO14230-2".equals(transportProtocol)) {
                    communicationProtocol = "K";
                }
                break;
            case "J1939-73":
            case "J1939":
                communicationProtocol = "1939";
                break;
        }
        return communicationProtocol;
    }

    //获取ASCII,BCD,HEX对应的规则产出
    private static String getABHFormula(CvEcuId cvEcuId, String order) {
        if (cvEcuId.getSubitemStartPlace() == null || cvEcuId.getSubitemDataLength() == null) {
            return "表格相关数据为空";
        }
        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuId.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuId.getSubitemDataLength());
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        String hexEndPosition = null;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 == 0 && subitemDataLength % 8 == 0) {
                Integer orderLength = 0;
                if (order.replace(" ","").length()%2!=0){
                    orderLength =order.replace(" ","").length() / 2 +1;
                }else{
                    orderLength =order.replace(" ","").length() / 2;
                }
                Integer startPosition = subitemStartPlace / 8 + orderLength + 06;
                //转换成16进制
                hexStartPosition = IntToHex.intToHex(startPosition);
                if (hexStartPosition.length() <= 1) {
                    hexStartPosition = "0" + hexStartPosition;
                }
                Integer endPosition = startPosition + subitemDataLength / 8;
                //转换成16进制
                hexEndPosition = IntToHex.intToHex(endPosition);
                if (hexEndPosition.length() <= 1) {
                    hexEndPosition = "0" + hexEndPosition;
                }
            } else {
                Integer orderLength = 0;
                if (order.replace(" ","").length()%2!=0){
                    orderLength =order.replace(" ","").length() / 2 +1;
                }else{
                    orderLength =order.replace(" ","").length() / 2;
                }
                Integer startPosition = 00 + orderLength + 06;
                //转换成16进制
                hexStartPosition = IntToHex.intToHex(startPosition);
                if (hexStartPosition.length() <= 1) {
                    hexStartPosition = "0" + hexStartPosition;
                }
                hexEndPosition = "FF";
            }

        }
        String formula = "{\"start_position\":\"" + hexStartPosition + "\",\"end_position\":\"" + hexEndPosition + "\"}";
        return formula;
    }

    //获取数值对应产出
    private static String getValueFormula(CvEcuId cvEcuId, String order) {
        if (cvEcuId.getSubitemStartPlace() == null || cvEcuId.getSubitemDataLength() == null) {
            return "表格相关数据为空";
        }

        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuId.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuId.getSubitemDataLength());
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        Integer subitemDataLengthResult = 0;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 != 0) {
                subitemStartPlace = subitemStartPlace / 8 + 1;
            }else{
                subitemStartPlace = subitemStartPlace / 8;
            }
            Integer orderLength = 0;
            if (order.replace(" ","").length()%2!=0){
                orderLength =order.replace(" ","").length() / 2 +1;
            }else{
                orderLength =order.replace(" ","").length() / 2;
            }
            Integer startPosition = subitemStartPlace + orderLength + 06;
            //转换成16进制
            hexStartPosition = IntToHex.intToHex(startPosition);
            if (hexStartPosition.length() <= 1) {
                hexStartPosition = "0" + hexStartPosition;
            }
            //取几位
            if(subitemDataLength%8!=0){
                subitemDataLengthResult = subitemDataLength / 8 + 1;
            }else{
                subitemDataLengthResult = subitemDataLength / 8;
            }

        }
//        String[] arr = {"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
//                "X0A", "X0B", "X0C", "X0D", "X0E", "X0F"
//                , "X10", "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19"
//                , "X1A", "X1B", "X1C", "X1D", "X1E", "X1F",
//                "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", "X29"
//        };
        String[] arr = arr1;
        String startPositionSub = "X" + hexStartPosition;
        String result = "";
        int iForRsult = 0;
        for (int i = 0; i < arr.length; i++) {
            if (startPositionSub.equals(arr[i])) {
                iForRsult = i;
            }
        }

        for (int i = iForRsult; i < (iForRsult + subitemDataLengthResult); i++) {
            result += arr[i];
        }
        String formula = "{\"Switch_Type\":\"[" + result + "]\"}";
        return formula;
    }

    //其他规则
    private static String getOther(CvEcuId cvEcuId, String order) {
        if (cvEcuId.getSubitemStartPlace() == null || cvEcuId.getSubitemDataLength() == null) {
            return "表格相关数据为空";
        }

        //转换类型
        Integer subitemStartPlace = Integer.valueOf(cvEcuId.getSubitemStartPlace());
        Integer subitemDataLength = Integer.valueOf(cvEcuId.getSubitemDataLength());
        //计算 start_position    subitemStartPlace 为8的倍数
        String hexStartPosition = null;
        Integer subitemDataLengthResult = 0;
        if (subitemStartPlace != null) {
            if (subitemStartPlace % 8 != 0) {
                subitemStartPlace = subitemStartPlace / 8 + 1;
            }else{
                subitemStartPlace = subitemStartPlace / 8;
            }
            Integer orderLength = 0;
            if (order.replace(" ","").length()%2!=0){
                orderLength =order.replace(" ","").length() / 2 +1;
            }else{
                orderLength =order.replace(" ","").length() / 2;
            }
            Integer startPosition = subitemStartPlace + orderLength + 06;
            //转换成16进制
            hexStartPosition = IntToHex.intToHex(startPosition);
            if (hexStartPosition.length() <= 1) {
                hexStartPosition = "0" + hexStartPosition;
            }
            //取几位
            if(subitemDataLength%8!=0){
                subitemDataLengthResult = subitemDataLength / 8 + 1;
            }else{
                subitemDataLengthResult = subitemDataLength / 8;
            }

        }
//        String[] arr = {"X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09",
//                "X0A", "X0B", "X0C", "X0D", "X0E", "X0F"
//                , "X10", "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19"
//                , "X1A", "X1B", "X1C", "X1D", "X1E", "X1F",
//                "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", "X29"
//        };
        String[] arr = arr1;
        String startPositionSub = "X" + hexStartPosition;
        String result = "";
        int iForRsult = 0;
        for (int i = 0; i < arr.length; i++) {
            if (startPositionSub.equals(arr[i])) {
                iForRsult = i;
            }
        }

        for (int i = iForRsult; i < (iForRsult + subitemDataLengthResult); i++) {
            result += arr[i];
        }
        return result;
    }
    //命令中需要每两个字节空一格
    public static String getFileAddSpace(String replace) {
        String regex = "(.{2})";
        replace = replace.replaceAll(regex, "$1 ");
        return replace;
    }

}
